﻿using System;
using System.Globalization;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
using MSVSIP = Microsoft.VisualStudio.Shell;

namespace CoryCissellMikeParks.Parkware_AutoShelve
{
    [Guid(GuidList.guidParkware_AutoShelveCmdSetString)]
    [ComVisible(true)]
    public partial class OptionsPageGeneral : MSVSIP.DialogPage
    {
        private int timerSaveInterval = 5;
        private string baseName = Resources.ExtensionName;

        public delegate void TimeIntervalChanged();
        public event TimeIntervalChanged OnIntervalChanged;


        public OptionsPageGeneral()
        {
            InitializeComponent();
        }

        public OptionsPageGeneral(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        [Category("Auto Save Settings")]
        [Description("The interval (in minutes) in which TFS Auto Shelve extension will automatically shelve workspaces.")]
        public int TimerSaveInterval
        {
            get
            {
                return timerSaveInterval;
            }
            set
            {
                if (value > 0)
                {
                    timerSaveInterval = value;
                }
                else
                {
                    WinFormsHelper.ShowMessageBox("TimerSaveInterval must be greater than 0.", "Error - Auto Shelve Settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        [Category("Auto Save Settings")]
        [Description("This name is automatically followed by the workspace name to create a unique shelveset name.")]
        public string BaseName
        {
            get
            {
                return baseName;
            }
            set
            {
                if (value.ToString().Length < 30)
                {
                    baseName = value;
                }
                else
                {
                    WinFormsHelper.ShowMessageBox("BaseName must be less than 30 characters.", "Error - Auto Shelve Settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }


        protected override void OnApply(MSVSIP.DialogPage.PageApplyEventArgs e)
        {
            base.OnApply(e);

            if (OnIntervalChanged != null)
            {
                OnIntervalChanged();
            }
        }
    }
}
